public class problem26 
{
	public static int lengthOfRecurringCycle( int n )
	{
		int[] quotients = new int[1000];
		int[] remainders = new int[1000];
 
		remainders[0] = 1;
		quotients[0] = 0;
 
		for( int i=1; i<quotients.length; i++ )
		{
			quotients[i] = remainders[i-1]*10/n;
			remainders[i] = remainders[i-1]*10 - quotients[i]*n;
 
			for( int j=1; j<i; j++ )
			{
				if( quotients[j] == quotients[i] && remainders[j] == remainders[i] )
				{
					return (i-j);
				}
			}
 
		}
 
		return -1;
	}
 
	public static void main(String[] args) 
	{
		int result = 0;		
		int maxLength = 0;
		int length;
 
		for( int i=1; i<1000; i++ )
		{
			length = lengthOfRecurringCycle(i);
 
			if( length > maxLength )
			{
				result = i;
				maxLength = length;
			}
		}
		System.out.println( maxLength );
		System.out.println( result );
	}
}